package organizer.ui;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import organizer.main.Day;

public class DayPanel extends JPanel {
	private Day day;
	private GridBagConstraints gbc = null;

	public Day getDay() {
		return day;
	}

	public void setDay(Day day) {
		this.day = day;
	}

	public DayPanel(Day day) {
		this.day = day;
		this.gbc = new GridBagConstraints();

		init();
		addComponents();
	}

	private void init() {
		setLayout(new GridBagLayout());
	}

	private void addComponents() {

		addTitle();

		addButtonPanel();
	}

	private void addTitle() {
		Date dayDate = day.getDate();
		String dateString = String.valueOf(dayDate);

		SimpleDateFormat sdf = new SimpleDateFormat("E, dd.MM.yyyy");
		dateString = sdf.format(dayDate);

		JLabel title = new JLabel(dateString);
		// add
		gbc.gridx = gbc.gridy = 0;
		add(title, gbc);
	}

	private void addButtonPanel() {
		JPanel buttonPanel = new JPanel();

		JButton plus = new JButton("+");
		buttonPanel.add(plus);

		JButton minus = new JButton("-");
		buttonPanel.add(minus);

		gbc.gridy++;
		add(buttonPanel, gbc);
	}

}

// package organizer.ui;
//
// import java.awt.Graphics;
// import java.awt.Image;
// import java.text.SimpleDateFormat;
// import java.util.Date;
//
// import javax.swing.JPanel;
//
// import organizer.resources.ResourceFactory;
//
// public class DayPanel extends JPanel {
// private Date date = null;
// private Image[] images = null;
//
// public Date getDate() {
// return date;
// }
//
// public void setDate(Date date) {
// this.date = date;
// }
//
// public DayPanel(Date date) {
// this.date = date;
//
// loadDayNumberImage();
// }
//
// private void loadDayNumberImage() {
// SimpleDateFormat sdf = new SimpleDateFormat("dd");
// String dayNumber = sdf.format(date);
// int length = dayNumber.length();
// images = new Image[length];
// for (int i = 0; i < length; i++) {
// images[i] = ResourceFactory.get().getImage("number" + i);
// }
// }
//
// @Override
// public void paintComponent(Graphics g) {
// for (int i = 0; i < images.length; i++) {
// int pos = images.length - i; // wrap counter (count from max -> 0)
// Image image = images[i];
// int w = image.getWidth(this);
// int h = image.getHeight(this);
// g.drawImage(images[i], 0, pos * w, w, h, this);
// }
// }
// }
